<template>
    <div>
       <!-- 顶部滑动条区域 -->
       <div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item',item.id==0?'mui-active':'']" 
                        v-for="item in cates" :key="item.id" @tap="getPhotoListByCateId(item.id)">
							{{item.title}}
						</a>
						
					</div>
				</div>

			</div>
         <!--图片列表区域-->   
    <ul class="photo-list">
  <router-link v-for="item in list" :key="item.id" :to="'/home/photoinfo/'+item.id" tag="li">
    <img v-lazy="item.img_url">
    <div class="info">
        <h1 class="info-title">{{item.title}}</h1>
        <div class="info-body">{{item.zhaiyao}}</div>
    </div>
  </router-link>
</ul>
    
    
    
    </div>
   
    
</template>
<script>
//1,导入mui的js
import mui from '../../lib/mui/js/mui.js'

/* //2,初始化滑动控件
mui('#slider').scroll({
	deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
}); */
export default {
    data(){
        return{
            cates:[],//所有分类的容器，列表数组
            list:[],//图片列表的数组
        };
    },
    created(){//在页面一加载的时候就调用
        this.getAllcategory();
        //默认进入页面就主动请求所有图片列表的数据
        this.getPhotoListByCateId(0);
    },
    methods:{
        getAllcategory(){
            //
            
            this.$http.get("http://localhost:3000/src/db/photoshare.json?id="+this.id).then(result=>{
                console.log(result);
                /* result.body.unshift({title:"全部",id:0}); */
                    this.cates=result.body;//给cates重新赋值
                
           
            });
        },
        getPhotoListByCateId(cateId){
            //根据分类id，获取图片列表
            this.$http.get('http://localhost:3000/src/db/photolist.json').then(result=>{
                console.log(result)
                this.list=result.body
            })
        }
    }
};
</script>
<style lang="scss" scoped>
.photo-list{
    list-style: none;
    margin: 0;
    padding: 10px;
    padding-bottom: 0 ;
    li{
        background-color: #ccc;
        text-align:center;
        margin-bottom: 10px;
        box-shadow: 0 0 9px #999;
        position: relative;
        img{
            width: 100%;
            vertical-align: middle;//解决图片底部撑不到问题，让图片撑满底部
        }
img[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
.info{
    color:white;
    text-align: left;
    position: absolute;
    bottom: 0;
    background-color: rgba(0,0,0,0.4);//实现背景半透明
    width: 100%;
    max-height:84px;//让盒子里的内容一致高度，超过文字的话，只显示高度范围的文字，实现美观
    .info-title{
        font-size: 15px;
    }
    .info-body{
        font-size: 14px;
        
    }
}
}}

</style>